package com.sz.jinzheng.until;

import com.sz.jinzheng.model.BillForm;
import com.sz.jinzheng.model.Result;
import com.sz.jinzheng.service.TbillFormService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * @Description: UserUntil
 * @author: Sheep
 * @date: 2021年07月07日 17:46
 */
@Slf4j
@Component
public class UserUntil {

    @Autowired
    private TbillFormService tbillFormService;

    public String getSalt() {
        //定义一个char数组
        char[] chars = ("ABCDEFGHIJKLMNOPIUYTQWZXC1234567890qwertyuiopasdfghjklzxcvbnm,./").toCharArray();
        //定义一个可变字符串
        StringBuilder s = new StringBuilder();
        //每次循环拿到6个从char数组中取出的数
        for (int i = 0; i < 6; i++) {
            //new Random().nextInt 表示随机生成从(o-chars.length)的数字
            char c = chars[new Random().nextInt(chars.length)];
            s.append(c);
        }
        return s.toString();
    }

    public String getPwd(String pwd, String salt) {
        pwd += salt;
        log.info("新密码=" + pwd);
        return DigestUtils.md5Hex(pwd);
    }


    /**
     * 生成验证码
     */
    public String getYzm() {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 6; i++) {//循环操作
            int random = (int) (Math.random() * 9);
            sb.append(random);
        }
        System.out.println("验证码：" + sb);
        return sb.toString();
    }




}
